package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.common.model.hosp.Hospital;
import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.common.vo.hosp.HospitalQueryVo;
import com.atguigu.yygh.hosp.service.HospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author LY
 */
@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation(value = "显示医院列表")
    @GetMapping("list/{page}/{limit}")
    public Result findPage( @ApiParam(name = "page", value = "当前页码", required = true)
                            @PathVariable Integer page,
                            @ApiParam(name = "limit", value = "每页记录数", required = true)
                            @PathVariable Integer limit,
                            @ApiParam(name = "hospitalQueryVo", value = "查询对象", required = false)
                            HospitalQueryVo hospitalQueryVo){
       Page<Hospital> hospitals =  hospitalService.findPage(page,limit,hospitalQueryVo);
        List<Hospital> content = hospitals.getContent();
        long elements = hospitals.getTotalElements();
        return Result.ok(hospitals);
    }

    @ApiOperation(value = "更新医院状态")
    @PutMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable String id,@PathVariable Integer status){
        //更新
        hospitalService.updateStatus(id,status);
        return Result.ok();
    }

    @ApiOperation(value = "查看医院详情")
    @GetMapping("show/{id}")
    public Result findById(@PathVariable String id){

       Map<String,Object> map =  hospitalService.getHospById(id);

       return Result.ok(map);
    }

}
